package com.xyc.manager.goods.controller;

import com.xyc.manager.global.Message;
import com.xyc.manager.goods.bean.GoodsTypeBean;
import com.xyc.manager.goods.service.GoodsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;
    @RequestMapping("type")
    @ResponseBody
    public List<GoodsTypeBean> returnWxbGoodTyoe(){
        List<GoodsTypeBean> goodsTypeBeans = goodsService.queryWxbTypeList();
        GoodsTypeBean goodsTypeBean = new GoodsTypeBean();
        goodsTypeBean.setId("00");

        goodsTypeBean.setOpen(true);
        goodsTypeBean.setName("分类管理");
        goodsTypeBean.setIcon("http://javen666.com:8080/fxmall/images/base.gif");
        goodsTypeBeans.add(0,goodsTypeBean);
        return goodsTypeBeans;
    }

    @RequestMapping("upstore-downstore")
    @ResponseBody
    public Message toMessage(Integer flag,@RequestParam("ids") String id){

        Message message = new Message();
        try {
            goodsService.updateState(flag,id);
            message.setCode(0);
        } catch (Exception e) {
            e.printStackTrace();
            message.setCode(1);
        }
        return message;
    }
}
